package com.zhy.deploy.config;

import cn.hutool.core.util.StrUtil;
import com.zhy.deploy.websocket.SocketMessage;
import java.io.File;

public class BuildMetadataBuilder {

    private BuildMetadata metadata;

    public BuildMetadataBuilder(){
        this.metadata = new BuildMetadata();
        this.setWorkspace(null);
    }

    public BuildMetadata build(){
        return metadata;
    }

    public BuildMetadataBuilder setWorkspace(String workspace){
        if(StrUtil.isEmpty(workspace)){
            String home = System.getenv("HOME");
            File workspaceFile = new File(home, ".deploy");
            if (!workspaceFile.exists()) {
                workspaceFile.mkdirs();
            }
            workspace = workspaceFile.getPath();
        }
        this.metadata.setWorkspace(workspace);
        return this;
    }

    public BuildMetadataBuilder setProjectName(String projectName){
        this.metadata.setProjectName(projectName);
        return this;
    }

    public BuildMetadataBuilder setSubProjectName(String subProjectName){
        this.metadata.setSubProjectName(subProjectName);
        return this;
    }

    public BuildMetadataBuilder message(SocketMessage message){
        this.metadata.setMessage(message);
        return this;
    }

    public BuildMetadataBuilder setGitConfig(GitConfig config){
        this.metadata.setGitConfig(config);
        return this;
    }

    public BuildMetadataBuilder setMavenConfig(MavenConfig config){
        this.metadata.setMavenConfig(config);
        return this;
    }

    public BuildMetadataBuilder setTomcatConfig(TomcatConfig config){
        this.metadata.setTomcatConfig(config);
        return this;
    }


}
